package com.tg.data.http.entity;

import android.os.Parcel;
import android.os.Parcelable;

import com.tg.appcommon.android.Packet;

public class SMsgAVIoctrlIPCONFIGRespBean implements Parcelable {
    public byte[] intf = new byte[16];
    public int  bDhcpEnabled;
    public byte[] ip = new byte[16];
    public byte[] netmask = new byte[16];
    public byte[] gateway = new byte[16];
    public byte[] dns1 = new byte[16];
    public byte[] dns2 = new byte[16];

    public void setIp(String ip) {
        byte[] ips = (ip == null || ip.length() == 0)? new byte[16] : ip.getBytes();
        System.arraycopy(ips, 0, this.ip, 0, ips.length);
    }

    public void setNetmask(String netmask) {
        byte[] netmasks = (netmask == null || netmask.length() == 0)? new byte[16] : netmask.getBytes();
        System.arraycopy(netmasks, 0, this.netmask, 0, netmasks.length);
    }

    public void setGateway(String gateway) {
        byte[] gateways = (gateway == null || gateway.length() == 0)? new byte[16] : gateway.getBytes();
        System.arraycopy(gateways, 0, this.gateway, 0, gateways.length);
    }

    public void setDns1(String dns1) {
        byte[] dns1s = (dns1 == null || dns1.length() == 0)? new byte[16] : dns1.getBytes();
        System.arraycopy(dns1s, 0, this.dns1, 0, dns1s.length);
    }


    public void setDns2(String dns2) {
        byte[] dns2s = (dns2 == null || dns2.length() == 0)? new byte[16] : dns2.getBytes();
        System.arraycopy(dns2s, 0, this.dns2, 0, dns2s.length);
    }

    public SMsgAVIoctrlIPCONFIGRespBean(){

    }

    public static SMsgAVIoctrlIPCONFIGRespBean build(byte[] data){
        SMsgAVIoctrlIPCONFIGRespBean sMsgAVIoctrlIPCONFIGRespBean = new SMsgAVIoctrlIPCONFIGRespBean();
        System.arraycopy(data, 0, sMsgAVIoctrlIPCONFIGRespBean.intf, 0, 16);
        sMsgAVIoctrlIPCONFIGRespBean.bDhcpEnabled = Packet.byteArrayToInt_Little(data, 16);
        System.arraycopy(data, 20, sMsgAVIoctrlIPCONFIGRespBean.ip, 0, 16);
        System.arraycopy(data, 36, sMsgAVIoctrlIPCONFIGRespBean.netmask, 0, 16);
        System.arraycopy(data, 52, sMsgAVIoctrlIPCONFIGRespBean.gateway, 0, 16);
        System.arraycopy(data, 68, sMsgAVIoctrlIPCONFIGRespBean.dns1, 0, 16);
        System.arraycopy(data, 84, sMsgAVIoctrlIPCONFIGRespBean.dns2, 0, 16);
        return sMsgAVIoctrlIPCONFIGRespBean;
    }

    protected SMsgAVIoctrlIPCONFIGRespBean(Parcel in) {
        intf = in.createByteArray();
        bDhcpEnabled = in.readInt();
        ip = in.createByteArray();
        netmask = in.createByteArray();
        gateway = in.createByteArray();
        dns1 = in.createByteArray();
        dns2 = in.createByteArray();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(intf);
        dest.writeInt(bDhcpEnabled);
        dest.writeByteArray(ip);
        dest.writeByteArray(netmask);
        dest.writeByteArray(gateway);
        dest.writeByteArray(dns1);
        dest.writeByteArray(dns2);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<SMsgAVIoctrlIPCONFIGRespBean> CREATOR = new Creator<SMsgAVIoctrlIPCONFIGRespBean>() {
        @Override
        public SMsgAVIoctrlIPCONFIGRespBean createFromParcel(Parcel in) {
            return new SMsgAVIoctrlIPCONFIGRespBean(in);
        }

        @Override
        public SMsgAVIoctrlIPCONFIGRespBean[] newArray(int size) {
            return new SMsgAVIoctrlIPCONFIGRespBean[size];
        }
    };


    public byte[] parseContent(int bDhcpEnabled, String ip, String mark, String gateway, String dns, String dns2) {
        byte[] result = new byte[100];
        System.arraycopy(intf, 0, result, 0, 16);

        byte[] ch = Packet.intToByteArray_Little(bDhcpEnabled);
        System.arraycopy(ch, 0, result, 16, 4);

        byte[] ips = (ip == null || ip.length() == 0)? new byte[16] : ip.getBytes();
        System.arraycopy(ips, 0, result, 20, ips.length);

        byte[] marks = (mark == null || mark.length() == 0)? new byte[16] : mark.getBytes();
        System.arraycopy(marks, 0, result, 36, marks.length);

        byte[] gateways = (gateway == null || gateway.length() == 0)? new byte[16] : gateway.getBytes();
        System.arraycopy(gateways, 0, result, 52, gateways.length);

        byte[] dnss = (dns == null || dns.length() == 0)? new byte[16] : dns.getBytes();
        System.arraycopy(dnss, 0, result, 68, dnss.length);

        byte[] dns2s = (dns2 == null || dns2.length() == 0)? new byte[16] : dns2.getBytes();
        System.arraycopy(dns2s, 0, result, 84, dns2s.length);

        return result;
    }

    public static byte[] parseContentEx(int bDhcpEnabled, String ip, String mark, String gateway, String dns, String dns2) {
        byte[] result = new byte[100];

        byte[] ch = Packet.intToByteArray_Little(bDhcpEnabled);
        System.arraycopy(ch, 0, result, 16, 4);

        byte[] ips = (ip == null || ip.length() == 0)? new byte[16] : ip.getBytes();
        System.arraycopy(ips, 0, result, 20, ips.length);

        byte[] marks = (mark == null || mark.length() == 0)? new byte[16] : mark.getBytes();
        System.arraycopy(marks, 0, result, 36, marks.length);

        byte[] gateways = (gateway == null || gateway.length() == 0)? new byte[16] : gateway.getBytes();
        System.arraycopy(gateways, 0, result, 52, gateways.length);

        byte[] dnss = (dns == null || dns.length() == 0)? new byte[16] : dns.getBytes();
        System.arraycopy(dnss, 0, result, 68, dnss.length);

        byte[] dns2s = (dns2 == null || dns2.length() == 0)? new byte[16] : dns2.getBytes();
        System.arraycopy(dns2s, 0, result, 84, dns2s.length);

        return result;
    }
}
